home *** CD-ROM | disk | FTP | other *** search
- Path: urals.jpl.nasa.gov!user
- From: mlj@tazboy.jpl.nasa.gov (Mose L. Johnson)
- Newsgroups: comp.lang.c++
- Subject: Re: Unresolved Templates during link time in Borderland 4.5
- Date: Fri, 26 Jan 1996 12:51:04 -0800
- Organization: Jet Propulsion Laboratory
- Message-ID: <mlj-2601961251040001@urals.jpl.nasa.gov>
- References: <mlj-2201960838180001@urals.jpl.nasa.gov>
- NNTP-Posting-Host: urals.jpl.nasa.gov
- Mime-Version: 1.0
- Content-Type: text/plain; charset=US-ASCII
- Content-Transfer-Encoding: 7bit
-
- This reply should have been posted to this Newsgroup.
-
- Organization: Infosoft Inc., Cupertino, CA, USA
-
- The problem is that, when the functions in your template class are compiled,
- you have to tell the compiler which versions are needed. I have found two
- ways that work with Borland C++.
-
- 1. The "lazy person's way" -- Just put both the header and the function
- bodies together in one file, and include that file wherever you use the
- template class. Of course, this will cause the template class's functions to
- be compiled multiple times, but the linker will throw out all but one copy.
-
- 2. To put the class in a .LIB file: Say its name is TClass.
-
- TClass.hpp (the header to be included where it is used) contains:
-
- #ifndef TCLASS_HPP
- #define TCLASS_HPP
-
- #ifndef TCLASS_CPP
- #pragma option -Jgx // Compile all function refs as external, except
- // when compiling TClass.cpp itself.
- #endif
-
- template <class T> class TClass {
- /* body */
- };
-
- /* "inline" functions, if any */
-
- #endif // TCLASS_HPP
-
- TClass.cpp (which compiles to become the library module) contains:
-
- #pragma option -Jgd // Compile function bodies here and export them!
-
- #define TCLASS_CPP
-
- #include "TClass.hpp"
-
- /* function bodies */
- --
- John David Galt I do not speak for my employer.
- jgalt@infosoft.com Send personal mail to: John_David_Galt@cup.portal.com
-